﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PhotoOfTheDay.Types
{
    public static class Scraper
    {

        public static string GetBefore(string raw, string stop)
        {
            if (raw.IndexOf(stop) < 0) return "";
            raw = raw.Substring(0, raw.IndexOf(stop));
            return raw;
        }

        public static string GetAfter(string raw, string start)
        {
            if (raw.IndexOf(start) < 0) return "";
            raw = raw.Substring(raw.IndexOf(start) + start.Length);
            return raw;
        }

        public static string GetAfterLast(string raw, string start)
        {
            if (raw.IndexOf(start) < 0) return "";
            raw = raw.Substring(raw.LastIndexOf(start) + start.Length);
            return raw;
        }

        public static string GetInnerDataRev(string raw, string LastEnd, string Start)
        {
            if (raw.IndexOf(LastEnd) < 0) return "";
            raw = raw.Substring(0, raw.IndexOf(LastEnd));
            if (raw.IndexOf(Start) < 0) return "";
            raw = raw.Substring(raw.LastIndexOf(Start));
            return raw;
        }

        public static string GetInnerData(string raw, string start, string stop)
        {
            if (raw.IndexOf(start) < 0) return "";
            raw = raw.Substring(raw.IndexOf(start) + start.Length);
            if (raw.IndexOf(stop) < 1) return "";
            raw = raw.Substring(0, raw.IndexOf(stop));
            return raw;
        }

        public static string GetAnchorURL(string raw)
        {
            if (raw.IndexOf("<a href=\"") < 0) return "";
            raw = raw.Substring(raw.IndexOf("<a href=\"") + "<a href=\"".Length);
            raw = raw.Substring(0, raw.IndexOf("\">"));
            return raw;
        }

    }
}
